package com.ease.model.typehandler;

import java.sql.SQLException;

import org.postgis.Geometry;
import org.postgis.PGgeometry;

import com.ease.model.util.PostgreSqlSpatialGeometryUtil;
import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;

/**
 * 
 * @author nathanleewei
 * 
 */
public class PgGeoLineTypeHandler extends PgGeometryTypeHandler {

	public PgGeoLineTypeHandler() {
		super();
	}

	private Object getResult(Object object) throws SQLException {
		if (null != object) {
			PGgeometry geometry = (PGgeometry) object;
			if (null != geometry && geometry.getGeoType() == Geometry.LINESTRING) {
				return PostgreSqlSpatialGeometryUtil.toGeoLine(geometry);
			}
		}
		return null;
	}

	// public Object getResult(CallableStatement cs, int columnIndex) throws
	// SQLException {
	// return getResult(cs.getObject(columnIndex));
	// }
	//
	// public Object getResult(ResultSet rs, int columnIndex) throws
	// SQLException {
	// return getResult(rs.getObject(columnIndex));
	// }
	//
	// public Object getResult(ResultSet rs, String columnName) throws
	// SQLException {
	// return getResult(rs.getObject(columnName));
	// }
	//
	// public void setParameter(PreparedStatement ps, int i, Object parameter,
	// String jdbcType) throws SQLException {
	// Connection conn = this.getOracleConnection(ps);
	// Assertion.notNull(conn, "OracleConnection not found");
	//
	// JGeometry geometry = OracleSpatialGeometryUtil.fromGeoLine((GeoLine)
	// parameter);
	// STRUCT struct = JGeometry.store(geometry, conn);
	// ps.setObject(i, struct);
	// }

	public Object valueOf(String s) {
		// TODO
		return null;
	}

	public void setParameter(ParameterSetter setter, Object parameter) throws SQLException {
		// PreparedStatement ps = setter.getPreparedStatement();
		// Connection conn = this.getOracleConnection(ps);
		// Assertion.notNull(conn, "OracleConnection not found");
		//
		// JGeometry geometry = PostgreSqlSpatialGeometryUtil.fromGeoLine((GeoLine) parameter);
		// STRUCT struct = JGeometry.store(geometry, conn);
		// ps.setObject(setter.getParameterIndex(), struct);
	}

	public Object getResult(ResultGetter getter) throws SQLException {

		return getResult(getter.getResultSet().getObject(getter.getColumnName()));
	}
}
